package com.shop.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shop.admin.dao.ShopStockDao;
import com.shop.admin.entity.ShopImage;
import com.shop.admin.entity.ShopStock;
import com.shop.admin.service.ShopStockService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ShopStockServiceImpl extends ServiceImpl<ShopStockDao, ShopStock> implements ShopStockService {
    @Override
    public void insertStock(ShopStock shopStock) {
        this.baseMapper.insert(shopStock);
    }

    @Override
    public ShopStock selectById(Integer stockId) {
       return this.baseMapper.selectOne(new QueryWrapper<ShopStock>().lambda().eq(ShopStock::getOrderId,stockId));
    }

    @Override
    public void updateStockCount(Long orderId, Integer stockCount) {
        ShopStock stock = new ShopStock();
        stock.setStockCount(stockCount);
        this.baseMapper.update(stock,new QueryWrapper<ShopStock>().lambda().eq(ShopStock::getOrderId,orderId));
    }

    @Override
    public void removeStockByOrderId(List<Long> asList) {
        for (Long aLong : asList) {
            this.baseMapper.delete(new QueryWrapper<ShopStock>().lambda().eq(ShopStock::getOrderId,aLong));
        }
    }

    @Override
    public List<ShopStock> selectCountList(List<Long> orderId) {
        return this.baseMapper.selectCountList(orderId);
    }

}
